package demo1;

public class Student {

    public String name = "kay";
    public int age = 20;
    public static String classRoom = "bit117";

    static {
        classRoom = "117Java";
        System.out.println("静态代码块被执行");
    }

    /*static {
        classRoom = "118Java";
        System.out.println("静态代码块被执行");
    }*/

    {
        this.name = "caocao";
        this.age = 100;
        System.out.println("实例代码块执行了,一般用来初始化实例数据成员");
    }

    /*{
        this.name = "bencao";
        this.age = 10;
        System.out.println("实例代码块执行了,一般用来初始化实例数据成员");
    }*/

    public Student(){
        System.out.println("不带参数的构造方法被执行了");
    }

    public Student(String name, int age){
        this.name = name;
        this.age = age;
        System.out.println("带两个参数的构造方法被执行了");
    }

    public void doClass(){
        // 非静态的可以调用静态的
        classRoom = "";
        getClassRoom();

        System.out.println(this.name + "学生正在上课...");
    }

    public static String getClassRoom(){
        // return Student.classRoom;
        /*this.name = "lisi";
        return this.name; //err*/

        // 真的想调用非静态的成员变量以及方法,就得重新创建对象
        Student student = new Student();
        student.name = "lisi";
        student.doClass();
        return " ";
    }
}
